$(document).ready(function () {
    init();
});

function init() {
    var path = location.href;
    var id = path.substring(path.lastIndexOf("/") + 1)

    $.ajax({
        url: "/commodity/findById",
        type: 'GET',
        data: {
            'id': id
        },
        dataType: "JSON",
        async: false,
        success: function (res) {
            var data2 = res.data2;
            var xlk = "";
            if (res.code == "200") {
                var data = res.data;
                $(".name").val(data.name);
                $(".price").val(data.price);
                $(".stock").val(data.stock);
                $(".createTime").val(data.createTime);
                for (var i = 0; i < data2.length; i++) {
                    xlk += "<option class='chosena' value=" + data2[i].id + ">" + data2[i].name + "</option>";
                }
                $("#contenta").html(xlk);
                var fl = [];
                for (var j = 0; j < res.data3.length; j++) {
                    fl.push(res.data3[j].id);
                }
                $("#contenta").val(fl);
                $("#contenta").trigger("chosen:updated");
            } else {
                alert(res.msg);
            }
        },
        error: function (e) {
            alert('发生错误')
        }
    })

}

function fanhui(){
    window.location.href = "/commoditylist";
}